#include<iostream>
#include<algorithm>
using namespace std;
const int N = 310;
struct node
{
	int a;
	int id;
	int w;
}s[N];
int cmp(node a, node b)
{
	if (a.w != b.w)return a.w > b.w;
	if (a.a != b.a)return a.a > b.a;
	return a.id < b.id;
}
int n;
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		int sum = a + b + c;
		s[i] = { a,i,sum };
	}
	sort(s + 1, s + n + 1, cmp);
	for (int i = 1; i <= 5; i++) {
		cout << s[i].id << " " << s[i].w << endl;
	}
	return 0;
}